'use strict';
/**
 * Created by FreezeSoul on 2015/9/30.
 */
define([
        'angular',
        'adConfig',
        'app/modules/roles/define',
        'app/modules/roles/services/roles'
    ],
    function (angular, adConfig) {
        angular.module('ad.roles')
            .controller('adRolesEditController', ['$scope', '$uibModalInstance', 'adRolesService', 'item', function ($scope, $uibModalInstance, service, item) {
                $scope.item = item;
                $scope.userRoleTypes = adConfig.userRoleTypes;

                $scope.ok = function () {
                    if (!item.role_id) {
                        service.addItem($scope.item).then(function (data) {
                            $uibModalInstance.close(data);
                        });
                    } else {
                        service.updateItem($scope.item).then(function (data) {
                            $uibModalInstance.close(data);
                        });
                    }

                };


                $scope.cancel = function () {
                    $uibModalInstance.dismiss('cancel');
                };
            }]);
    });